using FreeSql.DataAnnotations;
using SumerCoreDevOps.Shared.Enums;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 工作流步骤
/// </summary>
[Table(Name = "steps")]
[Index("idx_stage", nameof(StageId), false)]
public class Step
{
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 阶段ID
    /// </summary>
    public long StageId { get; set; }

    /// <summary>
    /// 步骤名称
    /// </summary>
    [Column(StringLength = 200)]
    public string Name { get; set; } = null!;

    /// <summary>
    /// 步骤类型
    /// </summary>
    public StepType StepType { get; set; }

    /// <summary>
    /// 执行顺序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 步骤配置（JSON格式）
    /// </summary>
    [Column(StringLength = -1)]
    public string StepConfig { get; set; } = "{}";

    /// <summary>
    /// 执行命令
    /// </summary>
    [Column(StringLength = -1)]
    public string? Command { get; set; }

    /// <summary>
    /// 超时时间（秒）
    /// </summary>
    public int TimeoutSeconds { get; set; } = 300;

    /// <summary>
    /// 最大重试次数
    /// </summary>
    public int MaxRetries { get; set; } = 0;

    /// <summary>
    /// 重试间隔（秒）
    /// </summary>
    public int RetryIntervalSeconds { get; set; } = 10;

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 阶段
    /// </summary>
    [Navigate(nameof(StageId))]
    public Stage Stage { get; set; } = null!;
}
